//
//  NSDate+Additions.m
//  MIYUE
//
//  Created by RanCheng on 15-1-13.
//  Copyright (c) 2015年 RanCheng. All rights reserved.
//

#import "NSDate+Additions.h"

@implementation NSDate (Additions)

-(NSInteger)age
{
    NSCalendar *cal = [NSCalendar currentCalendar];
    NSDateComponents *components = [cal components:NSCalendarUnitYear fromDate:self];
    int year0 = (int)[components year];
    
    NSDateComponents *components1 = [cal components:NSCalendarUnitYear fromDate:[NSDate date]];
    int year1 = (int)[components1 year];
    int diff = abs(year1-year0)+1;
    return diff;
}


-(NSString*)astro
{
    NSString *astroString = @"魔羯水瓶双鱼白羊金牛双子巨蟹狮子处女天秤天蝎射手魔羯";
    NSString *astroFormat = @"102123444543";
    NSString *result;
    NSCalendar *cal = [NSCalendar currentCalendar];
    NSDateComponents *components = [cal components:NSCalendarUnitMonth|NSDayCalendarUnit fromDate:self];
    int m = (int)[components month];
    int d = (int)[components day];
    result=[NSString stringWithFormat:@"%@",[astroString substringWithRange:NSMakeRange(m*2-(d < [[astroFormat substringWithRange:NSMakeRange((m-1), 1)] intValue] - (-19))*2,2)]];
    
    return [NSString stringWithFormat:@"%@座",result];
}


@end
